import { h } from "vue";
import { Modal } from "ant-design-vue";
import { LoadingOutlined } from "@ant-design/icons-vue";
export default class Common {
    /**
     * Singleton instance of Common
     * @type {Common}
     * @static
     */
    static sleep( ms ) {
        return new Promise( resolve => setTimeout( resolve, ms ) );
    }

    /**
     * format a number as a duration string
     * @param {*} number
     * @returns
     */
    static numberFormatAsDuration( number ) {
        number = Math.floor(number);
        let min = Math.floor( number / 60 );
        min = min < 10 ? '0' + min : min;
        let sec = number % 60;
        sec = sec < 10 ? '0' + sec : sec;
        return min + ':' + sec;
    }

    /**
     * show loading modal
     * @param {*} content
     */
    static loading() {
        return Modal.info({
            content: '',
            width: 70,
            footer:null,
            icon : h(LoadingOutlined),
            centered:true,
            closable:false,
            keyboard:false,
            maskClosable:false,
        });
    }
}
